﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    
    xmlns:WinChrome="clr-namespace:WinChrome;assembly=WinChrome" 
    xmlns:UI="clr-namespace:WinChrome.UI"
 >

    <Style TargetType="{x:Type UI:Flyout}">
     
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type UI:Flyout}">
                    <DockPanel x:Name="bd" Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="Resizing">
                                <VisualState x:Name="Expanded">                                    
                                    <Storyboard >
                                        <!--<ColorAnimation Storyboard.TargetName="header" Storyboard.TargetProperty="Background.Color"                                                
                                            To="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(WinChrome:VS2012.GlowColor)}"
                                            Duration="0:0:0.25"/>-->
                                        <ColorAnimation Storyboard.TargetName="headerText" Storyboard.TargetProperty="(TextElement.Foreground).Color"                                				
                                            To="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}"
                                            Duration="0:0:0.25"/>
                                        <ColorAnimation Storyboard.TargetName="marker" Storyboard.TargetProperty="Background.Color"
                            		        To="Transparent"
                                		    Duration="0:0:0.25"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="LockedOpen">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="header" Storyboard.TargetProperty="Background.Color"
                                				To="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}"
                                                Duration="0:0:0.25"/>
                                        <ColorAnimation Storyboard.TargetName="headerText" Storyboard.TargetProperty="(TextElement.Foreground).Color"                       
                                                To="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}"
                                                Duration="0:0:0.25"/>
                                        <ColorAnimation Storyboard.TargetName="marker" Storyboard.TargetProperty="Background.Color"
                                				To="Transparent"
                                				Duration="0:0:0.25"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Collapsed">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="header" Storyboard.TargetProperty="Background.Color"
                                				To="Transparent" Duration="0:0:0.25"/>
                                        <ColorAnimation Storyboard.TargetName="headerText" Storyboard.TargetProperty="(TextElement.Foreground).Color"                                				
                                				To="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}"
                                                Duration="0:0:0.25"/>
                                        <ColorAnimation Storyboard.TargetName="marker" Storyboard.TargetProperty="Background.Color"
                                				To="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}"
                                				Duration="0:0:0.25"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="header" DockPanel.Dock="Bottom">
                            <Grid.Background>
                                <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}"/>
                            </Grid.Background>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock x:Name="headerText" Margin="3">
                                <TextBlock.Foreground>
                                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}"/>
                                </TextBlock.Foreground>
                                <ContentPresenter 
                                              Content="{Binding Path=Header,RelativeSource ={RelativeSource FindAncestor, AncestorType={x:Type UI:Flyout}}}"/>
                            </TextBlock>
                            <ToggleButton IsChecked="{Binding Path=IsLockedOpen, RelativeSource={RelativeSource TemplatedParent}}" UseLayoutRounding="True"
                        			Focusable="False"
                        			Margin="3" Grid.Column="1"
                        			Background="{Binding Background, ElementName=header}">
                                <ToggleButton.Style>
                                    <Style TargetType="{x:Type ToggleButton}">
                                        <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                    <Border x:Name="btnBd" Background="{TemplateBinding Background}" Padding="3" RenderTransformOrigin="0.5,0.5">
                                                        <Path x:Name="path"  Data="F1M0,4L3,4 3,1 4,1 4,2 7,2 8,2 8,7 7,7 4,7 4,8 3,8 3,5 0,5 0,4z M7,3L4,3 4,5 7,5 7,3z" SnapsToDevicePixels="True" 
                                                              VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform"
                        										Fill="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" RenderTransformOrigin="0.5,0.5">
                                                            <Path.RenderTransform>
                                                                <TransformGroup>
                                                                    <RotateTransform x:Name="rotator" Angle="0"/>
                                                                </TransformGroup>
                                                            </Path.RenderTransform>
                                                        </Path>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsChecked" Value="True">
                                                            <Trigger.EnterActions>
                                                                <BeginStoryboard>
                                                                    <Storyboard>
                                                                        <DoubleAnimation Storyboard.TargetName="rotator" Storyboard.TargetProperty="Angle" To="-90" Duration="0:0:0.5"/>
                                                                    </Storyboard>
                                                                </BeginStoryboard>
                                                            </Trigger.EnterActions>
                                                            <Trigger.ExitActions>
                                                                <BeginStoryboard>
                                                                    <Storyboard>
                                                                        <DoubleAnimation Storyboard.TargetName="rotator" Storyboard.TargetProperty="Angle" To="0" Duration="0:0:0.5" />
                                                                    </Storyboard>
                                                                </BeginStoryboard>
                                                            </Trigger.ExitActions>
                                                        </Trigger>
                                                        <Trigger Property="IsMouseOver" Value="True" SourceName="btnBd">
                                                            <Setter Property="Background" TargetName="btnBd" Value="White"/>
                                                            <Setter TargetName="path" Property="Fill" >
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(WinChrome:VS2012.GlowColor)}" />
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Trigger>
                                                        <Trigger Property="IsPressed" Value="True">
                                                            <Setter Property="Background" TargetName="btnBd">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(WinChrome:VS2012.GlowColor)}" />
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Stroke" TargetName="path" Value="White"/>
                                                        </Trigger>

                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ToggleButton.Style>
                            </ToggleButton>
                        </Grid>
                        <Border x:Name="bdLeftRight" BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" BorderThickness="3,0,3,0" >
                            <DockPanel>
                                <Border x:Name="marker" DockPanel.Dock="Bottom" Height="3">
                                    <Border.Background>
                                        <SolidColorBrush Color="Transparent"/>
                                    </Border.Background>
                                </Border>
                                <ScrollViewer x:Name="sizer" VerticalScrollBarVisibility="Hidden" Background="{TemplateBinding Background}">
                                    <ContentPresenter x:Name="content"/>
                                </ScrollViewer>
                            </DockPanel>
                        </Border>
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="VerticalAlignment" Value="Bottom">
                            <Setter TargetName="header" Property="DockPanel.Dock" Value="Top"/>
                            <Setter TargetName="marker" Property="DockPanel.Dock" Value="Top"/>                            
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="header" Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(WinChrome:VS2012.GlowColor)}"/>
                                </Setter.Value>
                            </Setter>
                            <!--<Setter TargetName="headerText" Property="Foreground">
                                <Setter.Value>
                                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="marker" Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}"/>
                                </Setter.Value>
                            </Setter>-->
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="header" Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(WinChrome:VS2012.GlowColor)}"/>
                                </Setter.Value>
                            </Setter>
                            <!--<Setter TargetName="headerText" Property="Foreground">
                                <Setter.Value>
                                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="marker" Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}"/>
                                </Setter.Value>
                            </Setter>-->
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
